<?php get_instance()->view('common/header');?>
<div class="page-container home">
    <?php get_instance()->view('common/sidebar');?>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title"> <?php if($is_add):?>新增管理员 <?php else:?>编辑管理员<?php endif;?> </h3>
                    <ul class="page-breadcrumb breadcrumb">
                        <li class="btn-group"> <a class="btn default ml_5 return" href="<?php echo getUrl('setting/user');?>"><i class="fa fa-chevron-left"></i> 返回</a> </li>
                        <li><i class="fa fa-home"></i><a href="<?php echo getUrl('setting/user');?>">管理员  <i class="fa fa-angle-right"></i></a></li>
                        <li><a href="javascript:void(0);"><?php if($is_add):?>新增 <?php else:?>编辑<?php endif;?></a></li>
                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <!--开始-->

            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN VALIDATION STATES-->
                    <div class="portlet box">
                        <div class="portlet-body form">
                            <!-- BEGIN FORM-->
                            <form action="" class="form-horizontal" method="post" novalidate="novalidate">
                                <div class="form-body">
                                    <div class="form-group">
                                        <label class="control-label col-md-3">用户名  <span class="required">*</span></label>
                                        <div class="col-md-6">
                                            <input class="form-control required" name="name" value="<?php echo  $is_add ? '' : $admin['name'];?>" type="text">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3">是否超级管理员</label>
                                        <div class="col-md-6 text">
                                            <input type="checkbox" class="form-control" name="type" value="1" <?php if( ! $is_add && $admin['admin_type'] == 1):?>checked="true"<?php endif;?>/>
                                        </div>
                                    </div>
                                    <script type="text/javascript">
                                        $(function(){
                                            $('input[name="type"]').change(function(){
                                                if($(this).attr('checked')){
                                                    $('.dept-box,.postion-box').addClass('hide');
                                                }else{
                                                    $('.dept-box,.postion-box').removeClass('hide');
                                                }
                                            });
                                        });
                                    </script>
                                    <div class="form-group postion-box <?php if( ! $is_add && $admin['admin_type']):?>hide<?php endif;?>">
                                        <label class="control-label col-md-3">角色</label>
                                        <div class="col-md-6">
                                            <select class="form-control" name="role_id">
                                                <option></option>
                                                <?php foreach ($role as $v):?>
                                                    <option <?php if(! $is_add && $admin['role_id'] == $v['id']):?>selected="selected"<?php endif;?> value="<?php echo $v['id'];?>"><?php echo $v['name'];?></option>
                                                <?php endforeach;?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3">登录账号  <span class="required">*</span></label>
                                        <div class="col-md-6">
                                            <input class="form-control required " name="account" value="<?php echo ! $is_add ? $admin['account'] : '';?>" type="text">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3">登录密码 </label>
                                        <div class="col-md-6">
                                            <input class="form-control" id="password" minlength="6" name="password" value="" type="password">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-3">确认密码 </label>
                                        <div class="col-md-6">
                                            <input class="form-control" equalto="#password" name="repassword" value="" type="password">
                                        </div>
                                    </div>
                                </div>
                                <div class="form-actionsc fluid">
                                    <div class="col-md-offset-3 col-md-9">
                                    	<input type="hidden" name="id" value="<?php echo  $is_add ? '' : $admin['id'];?>">
                                        <button type="submit" class="btn green"><i class="fa fa-save"></i> 保存</button>
                                        <a href="<?php echo getUrl('setting/user');?>" class="btn default"><i class="fa fa-chevron-left"></i> 返回</a>
                                    </div>
                                </div>
                            </form>
                            <!-- END FORM-->
                        </div>
                    </div>
                    <!-- END VALIDATION STATES-->
                </div>
            </div>

            <!--结束-->
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){
    	$('select').select2();
        $.e_validate.init('.form-horizontal',{});
        // 手机号码验证
        jQuery.validator.addMethod("isMobile", function(value, element) {
            var length = value.length;
            var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
            return this.optional(element) || (length == 11 && mobile.test(value));
        }, "请正确填写您的手机号码");

        $(".form-horizontal").validate({
            rules : {
                account : {
                    required : true,
                    minlength : 11,
                    isMobile : true
                }
            },
            messages : {
                account : {
                    required : "请输入手机号",
                    minlength : "确认手机不能小于11个字符",
                    isMobile : "请正确填写您的手机号码"
                }
            },
            errorPlacement : function(error, element) {
                error.appendTo(element.next().next());
            },
            ignore : ".codeCls"
        });
    });
</script>
</body>
</html>